package org.example.niceoil.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.niceoil.dao.CustomerDao;
import org.example.niceoil.entity.*;
import org.example.niceoil.entity.Record;
import org.example.niceoil.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
public class Text {

    private CustomerDao customerDao;
    private  CustomerMapper customerMapper;
private ServiceMapper ServiceMapper;
private ManagerMapper ManagerMapper;
private RecordMapper RecordMapper;
private ViewRecordMapper ViewRecordMapper;
    @Autowired
    public Text(CustomerMapper customerMapper, CustomerDao customerDao, ViewRecordMapper ViewRecordMapper,ServiceMapper ServiceMapper,ManagerMapper ManagerMapper,RecordMapper RecordMapper) {
        this.customerMapper = customerMapper;
        this.customerDao = customerDao;
        this. ServiceMapper =ServiceMapper;
        this.ManagerMapper= ManagerMapper;
        this.RecordMapper=RecordMapper;
        this.ViewRecordMapper=ViewRecordMapper;
    }

    @GetMapping("/t1")
    public void get() {

    }

    @GetMapping("/de/{id}")
    public int de(@PathVariable int id) {
        return customerMapper.deleteById(id);

    }

    @GetMapping("/in")
    public Customer in() {
        Customer cu = new Customer();
        cu.setCupho("1321");
        cu.setCuname("gee222");
        cu.setCuname("wwww");
        System.out.println("=======:" + cu.getCuid());
        customerMapper.insert(cu);
        return cu;
    }

    @GetMapping("/sel/{name}")
    public List<Customer> sele(@PathVariable String name) {
        // 使用 QueryWrapper
        QueryWrapper<Customer> query = new QueryWrapper<>();
        query
//                .eq("cuid", 12); // 不等于
        .apply("LENGTH(cuname) = {0}", 10);  // 大于
//                .like("name", "张"); // 模糊查询包含“张”字的名字
        return customerMapper.selectList(query);
    }

    @GetMapping("/ser")
    public List<Service> ser(){
        return ServiceMapper.selectList(null);
    }

    @GetMapping("/ser2")
    public List<Manager> ser2(){
        return ManagerMapper.selectList(null);
    }
    @GetMapping("/ser3")
    public List<Record> ser3(){
        return RecordMapper.selectList(null);
    }
@GetMapping("/view")
    public List<ViewRecord> getview(){
        return ViewRecordMapper.selectList(null);
}

}
